package org.builder.web.tags;

import java.io.IOException;
import java.util.Map;

import javax.servlet.jsp.JspContext;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.el.ELException;
import javax.servlet.jsp.el.FunctionMapper;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.Tag;

import org.apache.commons.el.ExpressionEvaluatorImpl;
import org.apache.commons.el.parser.ELParser;
import org.apache.commons.lang.StringUtils;

public class GetMapValueTags extends BodyTagSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2338179099199228830L;

	private String key;

	private String value;

	private String map;

	public String getMap() {
		return map;
	}

	public void setMap(String map) {
		this.map = map;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {

		this.key = key;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public int doStartTag() throws JspException {
		String map = getMap();
		String keymap = getKey();
		System.out.println(pageContext);
		System.out.println("Try to find attribute: -->" + map + "<--");
		Object key = pageContext.findAttribute(keymap);
		Object obj = pageContext.findAttribute(map);
		try {
			System.out.println("BODY_CONTENT ZZZ==> " + pageContext.getOut());
			if (obj != null) {
				Map fieldsMap = (Map) obj;
				Object value = fieldsMap.get(key);
				if (value != null) {
					pageContext.getOut().print(value);
				}
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return SKIP_BODY;

	}

}
